package com.landeb.shop.huo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.landeb.shop.R;
import com.landeb.shop.huo.bean.BeanOrderFrag;

import java.util.ArrayList;
import java.util.List;

public class HorizonListviewAdapter extends BaseAdapter {

    private Context mContext;
    private LayoutInflater inflater = null;
    private List<BeanOrderFrag.DataBean.ListBean.GoodsBean> goods = new ArrayList<>();

    public HorizonListviewAdapter(Context context, List<BeanOrderFrag.DataBean.ListBean.GoodsBean> goods) {
        this.inflater = LayoutInflater.from(context);
        mContext = context;
        this.goods = goods;
    }

    @Override
    public int getCount() {
        return goods.size();
    }

    @Override
    public Object getItem(int position) {
        return goods.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();

            convertView = inflater.inflate(R.layout.item_horizon_lv, parent, false);

            holder.mImageView = (ImageView) convertView.findViewById(R.id.iv_item_horizon_lv);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        Glide.with(mContext)
                .load(goods.get(position).getPic())
                .placeholder(R.drawable.loading_pic)
                .error(R.drawable.error_pic)
                .into(holder.mImageView);

        return convertView;
    }

    class ViewHolder {

        ImageView mImageView;
    }

}
